<template>
  <div
    class="right-control-sidebar"
    :class="{ 'sidebar-visible': isVisible }"
    v-if="isVisible"
  >
    <div class="sidebar-content">
      <ul class="menu-list">
        <li
          v-for="(item, index) in menuItems"
          :key="index"
          class="menu-item"
          :class="{ 'menu-item-active': selectedIndex === index }"
          @click="handleMenuItemClick(item, index)"
        >
          <span class="menu-text">{{ item }}</span>
        </li>
      </ul>
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";

// 定义组件props
const props = defineProps({
  isVisible: {
    type: Boolean,
    default: false,
  },
});

// 组件内部定义菜单项
const menuItems = ref(["发电机", "趋势曲线", "参数设定", "报警事件"]);

// 定义组件事件
const emit = defineEmits(["menu-item-click", "close"]);

// 当前选中的菜单项索引
const selectedIndex = ref(0);

// 处理菜单项点击
const handleMenuItemClick = (item, index) => {
  selectedIndex.value = index;
  emit("menu-item-click", { item, index });
};
</script>

<style scoped>
.right-control-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: 120px;
  height: 100vh;
  background-color: #22474f;
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.2);
  z-index: 20;
  transition: transform 0.3s ease;
  transform: translateX(100%);
}

.sidebar-visible {
  transform: translateX(0);
}

.sidebar-content {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding-top: 20px;
}

.menu-list {
  list-style: none;
  padding: 0;
  margin: 0;
  flex: 1;
}

.menu-item {
  padding: 12px 8px;
  margin-bottom: 2px;
  cursor: pointer;
  transition: background-color 0.2s ease;
  background-color: #4a5c64;
  color: #ffffff;
  text-align: center;
  position: relative;
  border-bottom: 1px solid #22474f;
}

.menu-item:hover {
  background-color: #5a6c74;
}

.menu-item-active {
  background-color: #2a3c44;
  color: #ff0000;
  border-left: 4px solid #e1612e;
}

.menu-text {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 2px;
}

.menu-index {
  display: block;
  font-size: 12px;
  color: #cccccc;
}
</style>